<?php
    require_once(APPPATH . '/controllers/test/Toast.php');

    class realestate_thumbnails_again_tests extends Toast
    {

        function __construct()
        {
            parent::__construct(__FILE__);
            $this->load->helper('folder');
            $this->load->config('gallery');
            $this->load->library("gallery");
            $this->load->library("object_gallery_lib");
        }

        /*Delete all thumbnail directories for each gallery */
        public function delete_dir()
        {
            $this->load->model('objects_gallery_model');
            $obj_galleries = $this->objects_gallery_model->find_all_objects_galleries();

            // get thumbnail sizes
            $this->load->model("settings_model");

            // default thumbnails
            $this->settings_model->default_thumbnails();
            $thumbnails = $this->settings_model->list_thumbnails();

            // go troug each gallery
            foreach ($obj_galleries as $obj_gallery):

                // delete directories
                $this->object_gallery_lib->delete_thumbnails_dir($obj_gallery['objects_ID'],$thumbnails);

                endforeach;

        }

        //Create all thumbnail directories for each gallery
        function create_directories()
        {
            $this->load->model('objects_gallery_model');
            $obj_galleries = $this->objects_gallery_model->find_all_objects_galleries();

            // go troug each gallery
            foreach ($obj_galleries as $obj_gallery):
                $this->gallery->create_thumbnails_directories($obj_gallery['objects_ID']);
                endforeach;
        }

        //Create all thumbnail for each gallery picture
        function create_pictures()
        {
            $this->load->model('objects_gallery_model');
            $obj_galleries = $this->objects_gallery_model->find_all_objects_galleries();

            // find thumbnail sizes from db
            $this->load->model('settings_model');
            $thumbnails_sizes = $this->settings_model->list_thumbnails(TRUE);

            $this->load->library('pictures');

            // go troug each gallery
            foreach ($obj_galleries as $obj_gallery):

                // find gallery folder
                $folder = $this->object_gallery_lib->find_gallery_column($obj_gallery['objects_ID'],'path');

                // find pictures
                $pictures =  $this->gallery->view_list($obj_gallery['gallery_ID']);

                // create thumbnails
                $this->pictures->create_thumbnails($folder,$pictures,$thumbnails_sizes);

                endforeach;
        }

        function test_full()
        {
            $this->load->model('objects_gallery_model');
            $obj_galleries = $this->objects_gallery_model->find_all_objects_galleries();

            // get thumbnail sizes
            $this->load->model("settings_model");

            // default thumbnails
            $this->settings_model->default_thumbnails();
            $thumbnails = $this->settings_model->list_thumbnails();
            $thumbnails_sizes = $this->settings_model->list_thumbnails(TRUE);

            $this->load->library('pictures');

            // go troug each gallery
            foreach ($obj_galleries as $obj_gallery):

                // delete directories
                $this->object_gallery_lib->delete_thumbnails_dir($obj_gallery['objects_ID'],$thumbnails);

                // create directories
                $this->gallery->create_thumbnails_directories($obj_gallery['objects_ID']);

                // find gallery folder
                $folder = $this->object_gallery_lib->find_gallery_column($obj_gallery['objects_ID'],'path');

                // find pictures
                $pictures =  $this->gallery->view_list($obj_gallery['gallery_ID']);

                // create thumbnails
                $this->pictures->create_thumbnails($folder,$pictures,$thumbnails_sizes);

                endforeach;
        }
    }

?>